<template>
  <div>
    <el-cascader placeholder="请选择省市" @change="handleChange" :options="options" />
  </div>
</template>
<script>
import { regionDropDown } from "@/api/area";
export default {
  data() {
    return {
      options: []
    };
  },
  mounted() {
    this.getArea();
  },
  methods: {
    handleChange(value) {
      this.$emit("areafun", value);
    },
    // 省市区
    getArea() {
      regionDropDown().then(res => {
        const newArr = [];
        res.data.data.forEach((item1, index) => {
          newArr.push({
            value: item1.id,
            label: item1.name
          });
          if (item1.children != null) {
            newArr[index]["children"] = [];
            item1.children.forEach(item2 => {
              newArr[index]["children"].push({
                value: item2.id,
                label: item2.name
              });
            });
          }
        });
        this.options = newArr;
      });
    }
  }
};
</script>